﻿//https://leetcode.cn/problems/gray-code/submissions/601769193/?envType=problem-list-v2&envId=backtracking

class Solution {
public:
    vector<int> grayCode(int n)
    {
        vector<int> ret;
        ret.push_back(0);

        int head = 1;
        for (int i = 0; i < n; i++)
        {
            for (int j = ret.size() - 1; j >= 0; j--)
            {
                ret.push_back(head + ret[j]);
            }
            head <<= 1;
        }
        return ret;
    }
};
